<!-- 告警设置 -->
<template>
  <div class="q-pa-md bg-white warning-set-container">
    <div class="main_seting row">
      <span class="row">
        阀值上限
        <q-input
          outlined
          v-model="setList.up_value"
          dense
          class="q-px-sm"
          style="width: 200px"
          @update:model-value="setHealthScoreUp('up_value', setList.id)"
        />
      </span>
      <span>
        <q-checkbox
          dense
          v-model="setList.up_enable"
          @update:model-value="setHealthScoreUp('up_enable', setList.id)"
          label="使能通知"
        />
      </span>
    </div>
    <div class="main_seting row q-pt-md">
      <span class="row">
        阀值下限
        <q-input
          outlined
          v-model="setList.down_value"
          dense
          class="q-px-sm"
          style="width: 200px"
          @update:model-value="setHealthScoreUp('down_value', setList.id)"
        />
      </span>
      <span>
        <q-checkbox
          dense
          v-model="setList.down_enable"
          @update:model-value="setHealthScoreUp('down_enable', setList.id)"
          label="使能通知"
        />
      </span>
    </div>
  </div>
</template>

<script>
import { fetchSetupList, setSetupInfo } from 'src/api/systemtWarning'
export default {
  props: {
    setAssetId: {
      type: Number,
      default: 0
    }
  },
  data () {
    return {
      setList: {
        id: null,
        up_value: null,
        up_enable: false,
        down_value: null,
        down_enable: false
      }
    };
  },

  components: {
  },

  computed: {},

  mounted() {

  },
  watch: {
    setAssetId: {
      immediate: true,
      handler(val) {
        if (!val) return
        this.getSystemWarnDetail()
      }
    }
  },

  methods: {
    // 设置健康值上限/下限/是否通知
    setHealthScoreUp(params, listId) {
      if (this.setList[params] === '') return
      let setQuery = {}
      setQuery[params] = this.setList[params]
      this.setCurrentWarningDetail(listId, setQuery)

    },
    // 系统告警设置
    setCurrentWarningDetail(id, setQuery) {
      setSetupInfo(id, setQuery).then(res => {
        if (res.status === 200) {
          this.getSystemWarnDetail()
          this.$q.notify({
            type: 'positive',
            position: 'top',
            message: '设置成功！'
          })
        } else {
          this.setList = {
            up_value: null,
            up_enable: false,
            down_value: null,
            down_enable: false
          }
          this.$q.notify({
            type: 'warning',
            position: 'top',
            message: '设置失败！'
          })
        }
      })
    },
    // 获取值
    getSystemWarnDetail() {
      fetchSetupList({ equip_id: this.setAssetId }).then(res => {
        const setData = res.data
        this.setList = setData
      })
    },
  }
}

</script>
<style lang='scss' scoped>
.warning-set-container {
  height: 400px;
}
.main_seting {
  height: 40px;
  line-height: 40px;
}
</style>
